# Maintainer: Ariadne Conill <ariadne@dereferenced.org>
pkgname=uclient
pkgver=20210514
pkgrel=0
pkgdesc="ustream-based HTTP client library"
url="https://git.openwrt.org/project/uclient.git"
arch="all"
license="ISC"
depends=""
depends_dev="libubox-dev ustream-ssl-dev"
makedepends="cmake $depends_dev"
subpackages="$pkgname-dev $pkgname-fetch:_fetch"
_owrtgit=6a6011df
_owrtver="${pkgver:0:4}-${pkgver:4:2}-${pkgver:6:2}-${_owrtgit}"
source="https://sources.openwrt.org/uclient-${_owrtver}.tar.xz"
builddir="$srcdir/uclient-${_owrtver}"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

_fetch() {
	amove usr/bin/uclient-fetch
}

sha512sums="
91f0beccb367f39da998e46e160f5f73fcf7755f0ea88b72a970d9377efb5390deb6dd4d717a1b7b7cefffc61135cc1ffa24f1df78b87adb94a1a37b0b14abb3  uclient-2021-05-14-6a6011df.tar.xz
"
